package fast.loader;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;

public class ItemSetDB {
	
	HashMap<String,ItemSet> itemSetDB = new HashMap<String,ItemSet>();
	
	public ItemSetDB(){
		populateItemSetDB();
	}
	
	public ItemSetDB.ItemSet getItemSet(int id){
		if(itemSetDB.containsKey(id)){
			return itemSetDB.get(id);
		}
		System.out.println("unknown itemsetid: "+  id);
		return null;
	}
	
	public String getItemSetByItemId(int id){
		for(String name: itemSetDB.keySet()) {
			if(itemSetDB.get(name).contains(id))
				return name;
		}
		return null;
	}
	
	private void populateItemSetDB() {
		
		ItemSet s3 = new ItemSet();
		s3.add(77945);
		s3.add(77946);
		itemSetDB.put("Dagger_Stage_1", s3);
		
		ItemSet s5 = new ItemSet();
		s5.add(77947);
		s5.add(77948);
		itemSetDB.put("Dagger_Stage_2", s5);
		
		ItemSet s6 = new ItemSet();
		s6.add(77949);
		s6.add(77950);
		itemSetDB.put("Dagger_Stage_3", s6);
		
		ItemSet t14 = new ItemSet();
		t14.add(new int[]{85299,85300,85301,85302,85303}); // rogue normal
		t14.add(new int[]{86639,86640,86641,86642,86643}); // rogue lfr
		t14.add(new int[]{87124,87125,87126,87127,87128}); // rogue heroic
		t14.add(new int[]{85394,85395,85396,85397,85398}); // monk normal
		t14.add(new int[]{86734,86735,86736,86737,86738}); // monk lfr
		t14.add(new int[]{87084,87085,87086,87087,87088}); // monk heroic
		itemSetDB.put("T14", t14);
		
		ItemSet t15 = new ItemSet();
		t15.add(new int[]{95935,95306,95307,95305,95939,96683,95938,96682,95937,96681,95308,95936,95309,96680,96679}); // rogue
		itemSetDB.put("T15", t15);
		
		ItemSet t14_monk_tank = new ItemSet();
		t14_monk_tank.add(new int[]{87094,87095,87096,87097,87098}); // monk heroic tank
		t14_monk_tank.add(new int[]{86724,86725,86726,86727,86728}); // monk lfr tank
		t14_monk_tank.add(new int[]{85384,85385,85386,85387,85388}); // monk normal tank
		itemSetDB.put("T14_Tank", t14_monk_tank);
		
		ItemSet pvp_mop = new ItemSet();
		pvp_mop.add(new int[]{84848,84830,84868,84792,84913}); // rogue 483 season 12
		pvp_mop.add(new int[]{84995,85089,85055,85041,85023}); // rogue 483 season 12 elite
		pvp_mop.add(new int[]{84463,84464,84465,84466,84462}); // rogue 458 season 12
		pvp_mop.add(new int[]{88171,88172,88173,88174,88175}); // monk 458 season 12
		pvp_mop.add(new int[]{84547}); // FIXME some ids are missing or wrong
		pvp_mop.add(new int[]{84839,84857,84877,84902,84912}); // monk 483 season 12
		itemSetDB.put("pvp_mop", pvp_mop);
		
		// new PVP sets are done???
	}

	class ItemSet {
		int id;
		Set<Integer> items = new TreeSet<Integer>();
		
		public ItemSet(int id){
			this.id = id;
		}
		
		public ItemSet(){ }

		public void add(int i){
			items.add(i);
		}
		
		public void add(int[] i){
			for(int k = 0;k < i.length;k++){
				items.add(i[k]);
			}
		}
		
		public boolean contains(int i){
			return items.contains(i);
		}
	}
}

